#include <env.h>
#include <pmap.h>
#include <printf.h>

// Trivial temporary clock interrupt handler,
// called from clock_interrupt in locore.S
/*void
clock(void)
{
	printf("*");
}*/


// The real clock interrupt handler,
// implementing round-robin scheduling
	static int j=0;
void
sched_yield(void)
{

	unsigned int i;
	
	for(i = ++j%2; i<NENV ; i=(i+1)%NENV)	//envs[0] must be runnable
	{
		if(envs[i].env_status == ENV_RUNNABLE)
		{
			env_run(&envs[i]);
		
		}else{
			//env_run(&envs[1]);
		}
		
	}
	env_run(&envs[1]);
	panic("There is no process to run ! haha !\n");

}

